import urllib
from connect import *

# 搜索
def search(key):
    url = 'http://www.pixiv.net/search.php?'
    data = {
        's_mode': 's_tag',
        'word': key,
        'abt': 'y'
    }
    #完整url
    comurl = url+urllib.parse.urlencode(data)
    header = {
        "Accept": "application/json, text/javascript, */*; q=0.01",
        "Accept-Language": "zh-CN,zh;q=0.8",
        "Connection": "keep-alive",
        "Host": "www.pixiv.net",
        "Referer": comurl,
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
    }
    cookie = loadCookie()
    opener = getOpener(header, cookie)
    response = opener.open(comurl)
    return response.read()

